﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    public class Color : ICommandUIDefinition, IXmlBuildable
    {
        public string ColorName { get; set; }
        public string DisplayColor { get; set; }
        public int? Sequence { get; set; }
        public string Style { get; set; }
        public string Title { get; set; }

        public Color()
        {}

        public Color(XmlNode colorNode):this()
        {
            try
            {
                this.ColorName = XmlHelper.GetAttribute(colorNode, "Color");
                this.DisplayColor = XmlHelper.GetAttribute(colorNode, "DisplayColor");
                this.Sequence = XmlHelper.GetNullableIntAttribute(colorNode, "Sequence");
                this.Style = XmlHelper.GetAttribute(colorNode, "Style");
                this.Title = XmlHelper.GetAttribute(colorNode, "Title");
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void AddNode(XmlNode colorsXmlNode)
        {
            try
            {
                XmlNode colorXmlNode = XmlHelper.AddNode(colorsXmlNode, "Color");
                XmlHelper.AddAttribute(colorXmlNode, "Color", this.ColorName);
                XmlHelper.AddAttribute(colorXmlNode, "DisplayColor", this.DisplayColor);
                XmlHelper.AddAttribute(colorXmlNode, "Sequence", this.Sequence);
                XmlHelper.AddAttribute(colorXmlNode, "Style", this.Style);
                XmlHelper.AddAttribute(colorXmlNode, "Title", this.Title);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode node = new TreeNode("Color");
                node.Tag = this;
                node.ContextMenuStrip = ContextMenuStripHelper.BuildUICommandDefContextMenuStrip(node, null, true);

                parentNode.Nodes.Add(node);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
